/*
 * PI_REG.h
 *
 * Created: 24.10.2012 17:31:16
 *  Author: mariuvi
 */ 

/*!
 * @header		REG.h
 * @discussion	This file contains all declarations for the position controller.
*/		

#ifndef REG_H_
#define REG_H_


/*!
 * @function	REG_read_P
 * @discussion	Reads the proportional gain from a private variable.
 * @result		The proportional gain.
 */		
uint8_t REG_read_P();


/*!
 * @function	REG_read_D
 * @discussion	Reads the derivative gain from a private variable.
 * @result		The derivative gain.
 */		
uint8_t REG_read_D();


/*!
 * @function	REG_param_save
 * @discussion	Saves the gains to the EEPROM.
 * @param		P		The proportional gain.
 * @param		D		The derivative gain.
 * @result		None.
 */		
void REG_param_save(uint8_t P, uint8_t D);


/*!
 * @function	REG_param_load
 * @discussion	Loads the gains from the EEPROM into private variables.
 * @result		None.
 */		
void REG_param_load();


/*!
 * @function	REG_controller
 * @discussion	A PD regulator with a feedforward. Calculates the required output, given
				the position error and the elapsed time since last calculation.
 * @param		error	The position error, ie. the difference between the desired and current position.
 * @param		dt		The time elapsed since the last calculation.
 * @result		The speed needed to reach the desired position.
 */
int REG_controller(int error, float dt);


#endif /* REG_H_ */